home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Utilities Professional 1-1500
/
Utilities Professional 1-1500 (1994)(WPD)[!].iso
/
12511500
/
var1453.dms
/
var1453.adf
/
Lists
/
Example2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-02
|
3KB
|
115 lines
/***********************************************************/
/* */
/* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
/* ------------------------------- ------------------ */
/* */
/* Book: ACM System Amiga C Club */
/* Chapter: Lists Tulevagen 22 */
/* File: Example2.c 181 41 LIDINGO */
/* Author: Anders Bjerin SWEDEN */
/* Date: 92-05-01 */
/* Version: 1.00 */
/* */
/* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
/* */
/* Registered members may use this program freely in their */
/* own commercial/noncommercial programs/articles. */
/* */
/***********************************************************/
/* Demonstrates how to scan through a list from the head */
/* to the tail, and the other way around. */
#include <exec/types.h>
#include <exec/lists.h> /* This file will automatically */
/* include the file "nodes.h". */
/* Declare a complete node stucture: */
struct ToDo
{
struct Node node; /* Every node must have this. */
STRPTR Wish; /* Our own data. */
};
/* Declare a list structure: */
struct List my_list;
/* Node 1: */
struct ToDo eat=
{
{ NULL, NULL, NT_UNKNOWN, 0, "Eat" },
"eat"
};
/* Node 2: */
struct ToDo sleep=
{
{ NULL, NULL, NT_UNKNOWN, 0, "Sleep" },
"rest"
};
/* Node 3: */
struct ToDo drink=
{
{ NULL, NULL, NT_UNKNOWN, 0, "Drink" },
"drink"
};
main()
{
struct Node *ptr; /* Node pointer. */
/* Initialize our list structure: */
NewList( &my_list );
/* Add three nodes: */
printf( "Adding some nodes...\n" );
AddTail( &my_list, &eat );
AddTail( &my_list, &sleep );
AddTail( &my_list, &drink );
/* Scan from the head to the tail: */
printf( "We will now scan from the head to the tail...\n" );
/* Set the node pointer so it points to the first node: */
ptr = (struct Node *) my_list.lh_Head;
/* Stay in the loop as long as there is a node after this one: */
while( ptr->ln_Succ )
{
printf( "Node %s\n", ptr->ln_Name );
ptr = ptr->ln_Succ;
}
/* Scan from the tail to the head: */
printf( "We will now scan from the tail to the head...\n" );
/* Set the node pointer so it points to the last node: */
ptr = (struct Node *) my_list.lh_TailPred;
/* Stay in the loop as long as there is a node before this one: */
while( ptr->ln_Pred )
{
printf( "Node %s\n", ptr->ln_Name );
ptr = ptr->ln_Pred;
}
/* Remove all nodes from the list: */
printf( "Remove all nodes...\n" );
RemHead( &my_list, &eat );
RemHead( &my_list, &sleep );
RemHead( &my_list, &drink );
}